<?php
require_once dirname(__FILE__) . '/../../../incls/php/dbutils.class.php';
require_once dirname(__FILE__) . '/../../../incls/php/miscutils.class.php';
require_once dirname(__FILE__) . '/../../../incls/php/config.php';
$url = MiscUtils::getParam('url', NULL);
$page_id = MiscUtils::getParam('i', NULL);
$inst_id = MiscUtils::getParam('inid', NULL);
$folder = MiscUtils::getParam('infold', NULL);

$myPdo = DbUtils::createPdoInst();

$system_id = 0;
$cond_vals = new stdClass();
$cond_vals->c = 't.id = :v1';
$cond_vals->v = array(':v1' => $page_id);
$system_id = DbUtils::get($myPdo, 'pz2_page', $cond_vals, NULL, NULL, NULL, NULL, NULL)->d[0]->sys_id;

$cond_vals = new stdClass();
$cond_vals->c = 't.sys_id = :v1 AND t.parent_id = 0 AND t.is_visible = 1';
$cond_vals->v = array(':v1' => $system_id);
$pages = DbUtils::get($myPdo, 'pz2_page', $cond_vals, 't.order', 'ASC', NULL, NULL, NULL)->d;

?>
<style>
* {
  font-family: Trebuchet MS;
  font-size: 12px;
  outline: 0;
  margin: 0;
}
body {
  background-image: url(assets/imgs/bg.png);
  background-repeat: repeat;
}
.superscript {
  background-color: #653D3D;
  border-bottom: 1px solid #ddd;
  text-align: center;
}
.menubar td.menu {
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  background-color: #825050;
  min-width: 80px;
  border: 1px solid #825050;
  border-bottom: 0;
}
.menubar td.menu a {
  background-image: none !important;
  font-size: 14px;
  color: #fff;
  text-decoration: none;
  letter-spacing: 0;
  font-weight: bold;
}
.hi {
  background-color: #D9D6CD !important;
  border: 1px solid #D9D6CD;
  font-weight: bold;
}
.hi a {
  color: #825050 !important;
}
.right {
  text-align: center;
  vertical-align: middle;
  border-bottom: 0;
  font-size: 14px;
  font-family: Trebuchet MS;
  font-weight: bold;
}
.admin {
  background-color: #fed6c2;
  border: 1px solid #fed6c2;
  width: 60px;
}
.logout {
  background-color: #2bcb06;
  border: 1px solid #2bcb06;
  width: 80px;
}
.logout a {
  color: #fff;
  font-size: 14px;
  font-family: Lucida Sans Unicode;
  font-weight: bold;
  text-decoration: none;
}
.nav {
  height: 25px;
}
.nav a {
  color: #000; 
  font-weight: bold; 
  font-size: 14px;
}
.arrow {
  width: 20px;
  text-align: center;
  color: #aaa;
}
.image_button {
  background-color: #fff;
  border-bottom: 2px solid #666666;
  border-right: 2px solid #666666;
  border-top: 1px solid #bbbbbb;
  border-left: 1px solid #bbbbbb;
  font-weight: bold;
  cursor: pointer;
  display: inline-block;
  width: 60px;
  height: 25px;
  line-height: 25px;
  text-align: center;
  vertical-align: middle;
  color: #000;
}
.login_title {
  height: 50px;
  text-align: left;
  font-weight: 600;
  font-size: 20px;
  font-family: Trebuchet MS;
}
.account_td {
  width: 200px;
  height: 20px;
  text-align: left;
  font-weight: 400;
  font-size: 15px;
  font-family: Trebuchet MS;
  padding: 2px 0;
}
.password_td {
  width: 200px;
  height: 20px;
  text-align: left;
  font-weight: 400;
  font-size: 15px;
  font-family: Trebuchet MS;
  padding: 2px 0;
}
.login_input {
  width: 250px;
  height: 18px;
  font-family: Trebuchet MS;
}
.login_table {
  width: 700px;
  height: 300px;
}
</style>
<table cellpadding=0 cellspacing=0 width="250px">
  <tr><td class="login_title">Sign In</td></tr>
  <tr><td class="account_td">Account</td></tr>
  <tr><td><input id="account" type="text" class="login_input"></input></td></tr>
  <tr><td class="password_td">Password</td></tr>
  <tr><td><input id="password" type="password" class="login_input"></input></td></tr>
</table>
<div>&nbsp;</div>
<div class="image_button" onclick="login();">Login</div>
<script type="text/javascript" src="../../../libs/jquery/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
  function login() {
    var obj = {
      account: $('#account')[0].value,
      password: $('#password')[0].value
    };
    $.ajax({
      type: 'POST',
      url: '<?php echo basename(__FILE__, '.php'); ?>.server.php',
      data: 'action=login&q=' + encodeURIComponent(JSON.stringify(obj)),
      success: function(msg){
        try {
          if (JSON.parse(msg).length > 0) {
            parent.location.href = '<?php echo ($url) ? $url : 'http://' . URL . 'admin.php?i=' . $pages[0]->id ; ?>';
          }
        } catch (ex) {
        }
      }
    });
  }
</script>